<%@ page language="java" pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"   %>
<%@ include file="/common/taglibs.jsp" %>

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <%@ include file="/common/res-select2.jsp" %>
</head>
<body>
<div class="row">
    <div class="col-md-12">
        <form  method="post" id="inputForm" name="inputForm" class="form-horizontal" style="padding:5px 20px 0 0"  role="form">
            <div class="form-group">
                <label class="col-md-2 col-xs-2 control-label" for="batchName">批次名称</label>
                <div class="col-md-4 col-xs-4"  >
                    <input class="form-control"  name="batchName"   id="batchName"  type="text"  value="" placeholder="请输入批次名称">
                </div>
                <div class="col-md-4 col-xs-4" >
                <i  class="red">格式：小区名称-批次号</i>
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-2 col-xs-2 control-label" for="couponAmount">优惠券金额</label>
                <div class="col-md-4 col-xs-4"  >
                    <input class="form-control"  name="couponAmount"   id="couponAmount"  type="text"  value="" placeholder="请输入优惠券金额">
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-2 col-xs-2 control-label" for="couponNum">优惠券数量</label>
                <div class="col-md-4 col-xs-4"  >
                    <input class="form-control"  name="couponNum"    id="couponNum"  type="text"  value="" placeholder="请输入优惠券数量">
                </div>
                <div class="col-md-4 col-xs-4" >
                    <i class="red">一个批次生成数量小于等于500</i>
                </div>
            </div>

        </form>

    </div>
    <!--/.col-md-12-->
</div>
<!--/.row-->
<script>
    $(function () {
        var $inputForm = $('#inputForm');

        //ajax提交表单配置.
        var ajaxSubmitOption = {
            beforeSubmit: function () {
                //mask form,防止多次提交
                $inputForm.block()
            },
            success: function (resp, statusText) {
                $inputForm.unblock()
                P.messager({content:resp.msg,type:resp.success==true?'success':'error'}) ;
                window.refreshParentDataGrid();
                bootbox.hideAll();
                flushSelect();

            },
            url: P.ctx +  '/op/coupon/insert',
            type: 'post',
            dataType: 'json'
        };

        //jquery validate 验证表单
        $inputForm.validate({
            submitHandler: function (form) {
                //验证成功之后使用jquery form提交表单.
                $(form).ajaxSubmit(ajaxSubmitOption);
            },
            rules: {
                batchName: {
                    required: true,
                    maxlength: 50,
                    checkBatchName: true,
                    remote: {
                        url:P.ctx +  '/op/coupon/validate_batchname', //后台处理程序
                        type: 'post',               //数据发送方式
                        dataType: 'json'           //接受数据格式
                    }
                },
                couponAmount: {
                    required: true,
                    digits: true,
                    min:1
                },
                couponNum: {
                    required: true,
                    digits: true,
                    range:[1,500]
                }
            }, messages: {  //自定义提示消息.
                batchName: {
                    remote: '该批次名称已存在'
                }
            }
        }); //end validate

        //自定义正则表达示验证方法
        $.validator.addMethod("checkBatchName",function(value,element,params){
            var checkBatchName = /^[\u4e00-\u9fa5a-z0-9]+-[0-9]+$/;
            return this.optional(element)||(checkBatchName.test(value));
        },"*请输入正确的批次名称！");

    });//Dom ready
</script>
</body>
</html>